package com.fuxi.cloud.config;

import com.fuxi.cloud.common.interceptor.JimuReportInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * JimuReportConfiguration
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
@Configuration("jimuReportConfiguration")
@PropertySource({"classpath:config/default-config.properties"})
public class JimuReportConfiguration implements InitializingBean, WebMvcConfigurer {
    private static final Logger log = LoggerFactory.getLogger(JimuReportConfiguration.class);
    @Value("${jeecg.path.upload}")
    private String upLoadPath;
    @Value("${spring.resource.static-locations}")
    private String staticLocations;

    public JimuReportConfiguration() {
    }

    @Bean
    public JimuReportInterceptor jimuReportInterceptor() {
        return new JimuReportInterceptor();
    }

    public void addInterceptors(InterceptorRegistry registry) {
        String[] var2 = new String[]{"/*.js", "/*.css", "/*.svg", "/*.pdf", "/*.jpg", "/*.png", "/*.ico", "/*.html", "/html/**", "/js/**", "/css/**", "/images/**"};
        registry.addInterceptor(this.jimuReportInterceptor()).excludePathPatterns(var2).addPathPatterns(new String[]{"/jmreport/**"});
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        PropertySourcesPlaceholderConfigurer var0 = new PropertySourcesPlaceholderConfigurer();
        var0.setIgnoreUnresolvablePlaceholders(true);
        return var0;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info(" --- Init JimuReport Config --- ");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(new String[]{"/**"}).addResourceLocations(new String[]{"file:" + this.upLoadPath + "//"}).addResourceLocations(this.staticLocations.split(","));
    }
}
